running = True

while running :
    choose = input('1.十进制→二进制\t\t\t\t2.二进制→十进制\n请选择：')

    if choose == '1' :
        running = False
        ten = int(input('请输入十进制的数字（请输入正整数）\n:'))
        Cten = ten
        cache = []
        def ten_to_two():
            global two , ten
            two = ten
            ten = ten // 2
            two = two % 2
            cache.append(two)

        while ten != 0 :
            ten_to_two()
        cache = list(reversed(cache))
        cache = ''.join([str(i) for i in cache])
        print ('十进制的' , Cten , '=' , '二进制的' , cache)
        break

    if choose == '2' :
        running = False
        two = int(input('请输入二进制的数字（请输入正整数）\n:'))
        Ctwo = two
        two = list(str(two))
        l_long = len(two)

        c = int(max(two))
        if c >= 2 :
            print('输入不合法，请重新输入')
            running = True
        
        l = 0
        a = 0
        cache = 0

        while not l_long - (l + 1) == -1 :
            a = int(two[l]) * (2 ** (l_long - (l + 1)))
            l = l + 1
            cache = cache + a
        print('二进制的' , Ctwo , '=' , '十进制的' , cache)
        break